fn main(){
    let mut x = 5;//mut 让变量可以修改
    println!("The value of x is: {}",x);
    x = 6;//如果不是let mut x = 5，无法编译通过

    println!("The value of x is: {}",x);


    //const 声明常量, 必须显示声明类型,命名默认为全大写
    const MAX_POINTS: i32 = 100_000;
    // const min_points: i32 = 100_000;//必须大写，不然会警告

    let y = 6; // 对于重新绑定，不用写mut

    let y = y + MAX_POINTS;//使用let 重新绑定

    let y = y * 2;//使用let 重新绑定

    println!("The value of y is: {}",y);

    let spaces = "   ";
    let spaces = spaces.len();// 隐藏变量，spaces 被覆盖类型
    println!("The value of spaces is: {}", spaces);
    //let mut spaces = "   ";
    // spaces = spaces.len();// 编译错误，因为spaces 的类型 不一致

    let mut overflow : u8 = 255;
    // overflow += 1; // 编译错误，因为u8 类型最大值为255
    overflow = overflow - 1;
    println!("The value of overflow is: {}", overflow);

    let tup: (i32, f64, u8) = (500, 6.4, 1);
    let (_x, _y, _z) = tup;
    println!("The value of y is: {}", _y);

    let _first = tup.0;
    let _second = tup.1;
    let _third = tup.2;

    println!("The value of first is: {}", _first);

    let _a = [1, 2, 3, 4, 5];
    // [i32; 5] 声明数组类型和长度
    let a: [i32; 5] = [1, 2, 3, 4, 5];
    
    let b = [3; 5];// [3, 3, 3, 3, 3]

    let _first = a[0];

    let _second = a[1];

    for i in 0..5{
        println!("The value of a[{}] is: {}", i, a[i]);
        println!("The value of b[{}] is: {}", i, b[i]);
    }
    another_function();
    print_labeled_measurement/*参数*/(5, 'h');

    let x = 5;
    
    //表达式, 他会计算一个结果，然后返回这个结果
    let y = {
        let x = 3;
        x + 1 // 没有添加分号，他会返回x+1的结果，如果 添加分号，他就不会返回结果
    };

    println!("The value of x is: {}", x);
    println!("The value of y is: {}", y);

    let x = ten();
    
    println!("The value of x is: {}", x);

    let x = plus_one(x);

    println!("The value of x is: {}", x);

    let number = 3;
    //必须是bool值，不能是其他类型
    if number < 5 {
        println!("condition was true");
    } else {
        println!("condition was false");
    }

    if number != 0 {
        println!("number was something other than zero");
    } else if number %3 == 0 {
        println!("number was divisible by 3");
    } else if number % 2 == 0 {
        println!("number was divisible by 2");
    }else{
        println!("number was none of the above");
    }

    let condition = true;
    let number = if condition {
        5
    } else {
        6
    };

    println!("The value of number is: {}", number);

    let mut counter = 0;
    loop {
        counter += 1;
        println!("counter: {}", counter);
        if counter == 10 {
            break;
        }
    }

    // let + loop

    let mut count = 0;

    let result = loop {
        count += 1;

        if count == 5 {
            // break 语句会返回一个值，这个值就是 loop 语句中的表达式的值。
            break count * 2;
        }
    };

    println!("The result is {}", result);
    println!("count: {}", count);

    let mut number = 3;
    while number != 0 {
        println!("{}!", number);
        number -= 1;
        // continue;
        
    }

    println!("LIFTOFF!!!");

    let a = [10, 20, 30, 40, 50];
    for element in a.iter() {
        println!("the value is: {}", element);
        
    }
    for number in (1..4).rev() {
        println!("{}!", number);
    }
}

fn another_function() {
    println!("Another function.");
}

fn print_labeled_measurement(value: i32, unit_label: char) {
    println!("The measurement is: {}{}", value, unit_label);
}

fn ten() -> i32 {
    10
}

// 注意返回值的那一行没有分号;
// 如果加入分号会出现错误
fn plus_one(x: i32) -> i32 {
    x + 1
}